package cn.ecnu.mapper;

import cn.ecnu.pojo.Consultant;
import cn.ecnu.vo.toFront.RankVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface ConsultantMapper {

    /**
     * 根据咨询师ID获取咨询师信息
     *
     * @param consultantId 咨询师ID
     * @return 咨询师
     */
    @Select("SELECT * FROM psychology.consultant WHERE consultant_id = #{id}")
    Consultant getConsultantById(@Param("id") Integer consultantId);

    /**
     * 获取所有的咨询师
     *
     * @return 所有咨询师列表
     */
    @Select("SELECT * FROM psychology.consultant")
    List<Consultant> getAllConsultants();

    /**
     * 新增一个咨询师
     *
     * @param consultant 咨询师
     * @return 是否成功
     */
    int insertConsultant(Consultant consultant);

    /**
     * 根据督导ID获取和它绑定的咨询师信息
     *
     * @param supervisorId 督导ID
     * @return 绑定的咨询师列表
     */
    List<Consultant> getConsultantBySupervisorId(@Param("id") Integer supervisorId);

    // 获取咨询数排名前五的咨询师
    @Select("select to_id as userId, count(*) as count from consult_record group by to_id order by count(*) desc limit 5")
    List<RankVo> getCountRank();

    // 获取评分排名前五的咨询师
    @Select("select consultant_id as userId, consultant_grade as grade from consultant order by consultant_grade desc limit 5")
    List<RankVo> getGradeRank();


    int updateConsultant(Consultant consultant);
}
